package com.lenovo.smarttraffic.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.lenovo.smarttraffic.R;
import com.lenovo.smarttraffic.bean.MapPakerBean;
import com.lenovo.smarttraffic.bean.ParkExtra;

/**
 * Created by Caleb.F
 * on 2019-11-20
 * at 10:24
 */
public class ParkDetailActivity extends BaseActivity {
    private TextView mTvParkName;
    private TextView mTvLocation;
    private TextView mTvDistance;
    private TextView mTvMoney;
    private TextView mTvCarnumber;
    private TextView mTvPay;
    private ParkExtra MapPakerBean;
    private static final String TAG="ParkDetailActivity";
    private static final String PARK_DETAIL_INTENT="com.lenovo.smarttraffic.ui.activity.ParkDetailActivity.MapPakerBean";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        MapPakerBean = MapActivity.getIntentData(getIntent());
        setData();
    }

    private void setData() {
        mTvParkName.setText(MapPakerBean.getParkName());
        mTvCarnumber.setText(new StringBuilder().append(MapPakerBean.getLeftParkerCount()).append("/").append(MapPakerBean.getWholeParkerCount()));
        mTvDistance.setText(new StringBuilder().append(MapPakerBean.getParkDistance()).append("米"));
        mTvLocation.setText(new StringBuilder().append(MapPakerBean.getParkAddress()));
        mTvMoney.setText(new StringBuilder().append("每小时").
                append(MapPakerBean.getAverageRate()).append("元，最高").append(MapPakerBean.getMaxiumRate()).append("元/天"));
        mTvLocation.setOnClickListener(v->{
            Intent intent = new Intent(ParkDetailActivity.this, MapLineActivity.class);
            intent.putExtra(PARK_DETAIL_INTENT,new MapPakerBean(MapPakerBean.getCoordinate(),MapPakerBean.getParkName()));
            startActivity(intent);
        });

    }

    private void initView() {
        initToolBar("停车场详情");
        mTvParkName = findViewById(R.id.tv_park_name);
        mTvLocation = findViewById(R.id.tv_location);
        mTvDistance = findViewById(R.id.tv_distance);
        mTvMoney = findViewById(R.id.tv_money);
        mTvCarnumber = findViewById(R.id.tv_carnumber);
        mTvPay = findViewById(R.id.tv_pay);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_park_detail;
    }


    public static com.lenovo.smarttraffic.bean.MapPakerBean getParkInfo(Intent intent){
        return (com.lenovo.smarttraffic.bean.MapPakerBean) intent.getSerializableExtra(PARK_DETAIL_INTENT);
    }
}
